package com.jf.identity.filter;

import com.jf.identity.entity.OrgCode;
import com.jf.identity.util.OrgCodeCatchUtil;
import com.jf.identity.util.Params;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 校验orgCode
 *
 * @author FCG
 */
@Component
public class OrgCodeHandler implements ParamHandler<Object, OrgCode> {
    @Resource
    private OrgCodeCatchUtil orgCodeCatchUtil;

    @Override
    public Object handle(OrgCode param, HttpServletRequest request, HttpServletResponse response) {

        OrgCode orgCode = Params.isBlank(param, "orgCode");
        String orgCodeStr = Params.isBlank(orgCode.getOrgCode(), "orgCode");
        String orgIdenCode = Params.isBlank(orgCode.getOrgIdenCode(), "orgIdenCode");
        Map<String, String> orgCodeMap = orgCodeCatchUtil.getOrgCodeCatch();
        if (orgCodeMap.containsKey(orgCodeStr)) {
            if (!orgCodeMap.get(orgCode.getOrgCode()).equals(orgIdenCode)) {
                throw new IllegalArgumentException("orgIdenCode无效");
            }
        } else {
            throw new IllegalArgumentException("orgCode无效");
        }
        return null;
    }

}




















